/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package aptech.semester.code.gui;

import aptech.semester.code.common.ApplicationCommon;
import aptech.semester.code.common.Constants;
import aptech.semester.code.data.DepartmentList;
import aptech.semester.code.data.EmployeeList;
import aptech.semester.code.data.EmployeeSalaryList;
import aptech.semester.code.data.SalaryFormList;
import aptech.semester.code.entity.DepartmentEntity;
import aptech.semester.code.entity.EmployeeEntity;
import aptech.semester.code.entity.EmployeeSalaryEntity;
import aptech.semester.code.entity.SalaryFormEntity;
import aptech.semester.code.item.DepartmentComboItem;
import aptech.semester.code.renderer.TableCellTextFieldRenderer;
import com.toedter.calendar.JMonthChooser;
import java.awt.Dimension;
import java.math.BigDecimal;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.Vector;
import javax.swing.JFileChooser;
import javax.swing.JOptionPane;
import javax.swing.SpinnerNumberModel;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableColumn;

/**
 *
 * @author vi
 */
public class EmployeeSalary extends javax.swing.JInternalFrame {

    /**
     * Creates new form EmployeeSalary
     */
    public EmployeeSalary(MainScreen mainFrame) {
        initComponents();
        initData();
        btnCalculate.setEnabled(false);
        btnExport.setEnabled(false);
        setSize(new Dimension(mainFrame.getWidth() - 5, mainFrame.getHeight() - 91));
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jLabel3 = new javax.swing.JLabel();
        cbDepartment = new javax.swing.JComboBox();
        jLabel11 = new javax.swing.JLabel();
        jLabel12 = new javax.swing.JLabel();
        sprinnerWorkingDay = new javax.swing.JSpinner();
        chooserMonth = new JMonthChooser(false)
        ;
        jLabel1 = new javax.swing.JLabel();
        chooserYear = new com.toedter.calendar.JYearChooser();
        btnLoadData = new javax.swing.JButton();
        jPanel2 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        tblEmployee = new javax.swing.JTable();
        jPanel4 = new javax.swing.JPanel();
        btnCalculate = new javax.swing.JButton();
        btnExport = new javax.swing.JButton();

        setClosable(true);
        setResizable(true);
        setTitle("Salary");
        setPreferredSize(new java.awt.Dimension(1000, 600));

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("General"));

        jLabel3.setText("Month");

        jLabel11.setText("Department");

        jLabel12.setText("Working Day");

        chooserMonth.setYearChooser(chooserYear);
        chooserMonth.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
            public void propertyChange(java.beans.PropertyChangeEvent evt) {
                chooserMonthPropertyChange(evt);
            }
        });

        jLabel1.setText("Year");

        chooserYear.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                chooserYearMouseClicked(evt);
            }
        });
        chooserYear.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
            public void propertyChange(java.beans.PropertyChangeEvent evt) {
                chooserYearPropertyChange(evt);
            }
        });

        btnLoadData.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/icon/load.png"))); // NOI18N
        btnLoadData.setText("Load Data");
        btnLoadData.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnLoadDataActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel3)
                .addGap(18, 18, 18)
                .addComponent(chooserMonth, javax.swing.GroupLayout.PREFERRED_SIZE, 119, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel1)
                .addGap(18, 18, 18)
                .addComponent(chooserYear, javax.swing.GroupLayout.PREFERRED_SIZE, 98, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(jLabel11)
                .addGap(30, 30, 30)
                .addComponent(cbDepartment, javax.swing.GroupLayout.PREFERRED_SIZE, 175, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(43, 43, 43)
                .addComponent(jLabel12)
                .addGap(18, 18, 18)
                .addComponent(sprinnerWorkingDay, javax.swing.GroupLayout.PREFERRED_SIZE, 70, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(btnLoadData, javax.swing.GroupLayout.PREFERRED_SIZE, 119, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(24, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                .addComponent(cbDepartment, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addComponent(jLabel11)
                .addComponent(jLabel12)
                .addComponent(sprinnerWorkingDay, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addComponent(btnLoadData))
            .addComponent(chooserYear, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                .addComponent(jLabel1)
                .addComponent(chooserMonth, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addComponent(jLabel3))
        );

        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder("Employees"));

        tblEmployee.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Employee ID", "Employee Name", "Basic Salary", "Bonus Position", "Working Day", "Over Time (hours)", "Anual Leave", "Leave Without Salary", "Bonus Plus (+)", "Bonus Sub (-)", "Salary"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.String.class, java.lang.String.class, java.lang.Double.class, java.lang.Double.class, java.lang.Integer.class, java.lang.Integer.class, java.lang.Double.class, java.lang.Double.class, java.lang.Double.class, java.lang.Double.class, java.lang.Double.class
            };
            boolean[] canEdit = new boolean [] {
                false, false, false, false, true, true, true, true, true, true, true
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        tblEmployee.setRowHeight(30);
        tblEmployee.getTableHeader().setReorderingAllowed(false);
        jScrollPane1.setViewportView(tblEmployee);
        if (tblEmployee.getColumnModel().getColumnCount() > 0) {
            tblEmployee.getColumnModel().getColumn(0).setPreferredWidth(25);
            tblEmployee.getColumnModel().getColumn(1).setPreferredWidth(25);
            tblEmployee.getColumnModel().getColumn(4).setPreferredWidth(10);
            tblEmployee.getColumnModel().getColumn(5).setPreferredWidth(10);
        }

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane1)
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 416, Short.MAX_VALUE)
        );

        jPanel4.setBorder(javax.swing.BorderFactory.createTitledBorder("Command"));

        btnCalculate.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/icon/calculate.png"))); // NOI18N
        btnCalculate.setText("Calculate");
        btnCalculate.setEnabled(false);
        btnCalculate.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnCalculateActionPerformed(evt);
            }
        });

        btnExport.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/icon/excel.png"))); // NOI18N
        btnExport.setText("Export to Excel");
        btnExport.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnExportActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel4Layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(btnExport)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(btnCalculate)
                .addContainerGap())
        );
        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                .addComponent(btnCalculate)
                .addComponent(btnExport))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents
    List<EmployeeSalaryEntity> listEmpSalary;
    private void btnLoadDataActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnLoadDataActionPerformed
        if (validateLoadData()) {
            loadData();
        }
    }//GEN-LAST:event_btnLoadDataActionPerformed

    private void btnCalculateActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCalculateActionPerformed
        List<EmployeeSalaryEntity> listEmpSalary = new ArrayList<EmployeeSalaryEntity>();
        DepartmentComboItem item = (DepartmentComboItem)cbDepartment.getSelectedItem();
        DepartmentEntity department = item.getValue();
        if (currentSalaryForm.getSalaryFormId() <= 0) {
            currentSalaryForm.setYearCalculate(year);
            currentSalaryForm.setTotalWorkingDay(Integer.parseInt(sprinnerWorkingDay.getValue().toString()));
            currentSalaryForm.setMonthCalculate(month);
            currentSalaryForm.setDepartment(department.getDepartmentId());
          
            currentSalaryForm.setSalaryFormId(new SalaryFormList().insert(currentSalaryForm));
        }
        
        DefaultTableModel model = (DefaultTableModel)tblEmployee.getModel();
        Vector data = model.getDataVector();
        DecimalFormat df = new DecimalFormat("#.#");
        for (int i = 0; i < data.size(); i++) {
            Vector row = (Vector) data.elementAt(i);
            EmployeeSalaryEntity empSalary = new EmployeeSalaryEntity();
            String employeeId = row.elementAt(0).toString();
            empSalary.setEmployeeId(employeeId);
            String empName = row.elementAt(1).toString();
            empSalary.setEmployeeName(empName);
            float basicSalary = new Float(row.elementAt(2).toString());
            empSalary.setBasicSalary(new BigDecimal(row.elementAt(2).toString()));
            float bonusPosition = new Float(row.elementAt(3).toString());
            
            int workingDay = Integer.parseInt(row.elementAt(4).toString());
            empSalary.setWorkingDate(workingDay);
            int overtime = Integer.parseInt(row.elementAt(5).toString());
            empSalary.setOvertime(overtime);
            float anualLeave = new Float(row.elementAt(6).toString());           
            empSalary.setDayOffInspect(anualLeave);
            float leaveWithoutSalary = new Float(row.elementAt(7).toString());
            empSalary.setDayOffNoSalary(leaveWithoutSalary);
            float bonusPlus = new Float(row.elementAt(8).toString());
            empSalary.setBonusPlus(new BigDecimal(row.elementAt(8).toString()));
            float bonusSub = new Float(row.elementAt(9).toString());
            empSalary.setBonusSub(new BigDecimal(row.elementAt(9).toString()));
            
            int sumaryWorkingDay = Integer.parseInt(sprinnerWorkingDay.getValue().toString());
            float salaryPerDay = 0;
            if (sumaryWorkingDay != 0) {        
                salaryPerDay = basicSalary / sumaryWorkingDay;
            }
            float totalSalary = 0F;
//            if (month != Calendar.DECEMBER) {
//                totalSalary = (salaryPerDay * workingDay) + (bonusPosition + bonusPlus) + ((overtime / 8) * salaryPerDay * Constants.COEFFICIENT_OVERTIME) - (bonusSub + (salaryPerDay * (float)leaveWithoutSalary));
//            } else {
//                float totalAnual = getTotalAnualLeaveOfEmployee(employeeId) + anualLeave;
//                float resultAnual = Constants.MAX_ANUAL_LEAVE_IN_YEAR - totalAnual;
//                totalSalary = (salaryPerDay * workingDay) + (bonusPosition + bonusPlus) + ((overtime / 8) * salaryPerDay * Constants.COEFFICIENT_OVERTIME) - (bonusSub + (salaryPerDay * (float)leaveWithoutSalary)) + ((float)resultAnual * salaryPerDay);
//            }
            float annualLeave = empSalary.getDayOffInspect();
            totalSalary = (salaryPerDay * workingDay) + (bonusPosition + bonusPlus + annualLeave*salaryPerDay) + ((overtime / 8) * salaryPerDay * Constants.COEFFICIENT_OVERTIME) - (bonusSub);
            
            
            empSalary.setTotalSalary(new BigDecimal(totalSalary));
            empSalary.setSalaryForm(currentSalaryForm.getSalaryFormId());
            listEmpSalary.add(empSalary);
        }
        
        // insert to database
        new EmployeeSalaryList().insertListEmployeeSalary(listEmpSalary);
        
        loadData();

        tblEmployee.repaint();
        btnExport.setEnabled(true);
    }//GEN-LAST:event_btnCalculateActionPerformed

    private void chooserMonthPropertyChange(java.beans.PropertyChangeEvent evt) {//GEN-FIRST:event_chooserMonthPropertyChange
        month = chooserMonth.getMonth();
        getMaxDaysInMonth();
    }//GEN-LAST:event_chooserMonthPropertyChange

    private void chooserYearPropertyChange(java.beans.PropertyChangeEvent evt) {//GEN-FIRST:event_chooserYearPropertyChange
        year = chooserYear.getYear();
        getMaxDaysInMonth();
    }//GEN-LAST:event_chooserYearPropertyChange

    private void btnExportActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnExportActionPerformed
        JFileChooser fc = new JFileChooser();
        int option = fc.showSaveDialog(this);
        
        if (option == JFileChooser.APPROVE_OPTION) {
            String filename = fc.getSelectedFile().getName();
            String path = fc.getSelectedFile().getParentFile().getPath();

            int len = filename.length();
            String ext = "";
            String file = "";

            if (len > 4) {
                ext = filename.substring(len - 4, len);
            }

            if (ext.equals(".xls")) {
                file = path + "\\" + filename;
            } else {
                file = path + "\\" + filename + ".xls";
            }
            
            new ApplicationCommon().writeToExcell(tblEmployee, file,"REPORT SALARY IN "+chooserMonth.getMonth()+" / "+chooserYear.getYear());
        }
    }//GEN-LAST:event_btnExportActionPerformed

    private void chooserYearMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_chooserYearMouseClicked
        // TODO add your handling code here:
    }//GEN-LAST:event_chooserYearMouseClicked


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnCalculate;
    private javax.swing.JButton btnExport;
    private javax.swing.JButton btnLoadData;
    private javax.swing.JComboBox cbDepartment;
    private com.toedter.calendar.JMonthChooser chooserMonth;
    private com.toedter.calendar.JYearChooser chooserYear;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JSpinner sprinnerWorkingDay;
    private javax.swing.JTable tblEmployee;
    // End of variables declaration//GEN-END:variables
    private DepartmentEntity selectedDepartment = new DepartmentEntity();
    private SalaryFormEntity currentSalaryForm;
    private int month = -1;
    private int year = 0;
    
    private void initData() {
        // binding data for department
        List<DepartmentEntity> listDept = new DepartmentList().getAllDepartment();
        for (DepartmentEntity dept : listDept) {
            cbDepartment.addItem(new DepartmentComboItem(dept));   
        }
        //sprinnerWorkingDay.setValue(new Integer(23));
        
        
        if (cbDepartment.getItemCount() > 0) {
            DepartmentComboItem item = (DepartmentComboItem)cbDepartment.getItemAt(0);
            selectedDepartment = item.getValue();
        }
    }
    
    private void loadData() {
        DepartmentComboItem item = (DepartmentComboItem)cbDepartment.getSelectedItem();
        DepartmentEntity department = item.getValue();
        SalaryFormEntity salaryForm = new SalaryFormList().getSalaryFormByDateAndDept(year, month,department.getDepartmentId());
        DefaultTableModel model = (DefaultTableModel)tblEmployee.getModel();
        model.setRowCount(0);
        listEmpSalary = new ArrayList<EmployeeSalaryEntity>();
        if (salaryForm.getSalaryFormId() <= 0) {
            currentSalaryForm = new SalaryFormEntity();
            
            // disable button calculate
            btnCalculate.setEnabled(true);
            btnExport.setEnabled(false);
            
            
            List<EmployeeEntity> listEmp = new EmployeeList().getEmployeeByDepartment(department.getDepartmentId());
            
            for(EmployeeEntity emp : listEmp) {
                EmployeeSalaryEntity empSalary = new EmployeeSalaryEntity();
                empSalary.setEmployeeId(emp.getEmployeeId());
                empSalary.setEmployeeName(emp.getName());
                empSalary.setWorkingDate((Integer)sprinnerWorkingDay.getValue());
                empSalary.setOvertime(0);
                empSalary.setDayOffNoSalary(0);
                empSalary.setDayOffInspect(0);
                empSalary.setBonusPlus(BigDecimal.ZERO);
                empSalary.setBonusSub(BigDecimal.ZERO);
                empSalary.setTotalSalary(BigDecimal.ZERO);
                empSalary.setBonusSalary(emp.getBonusSalary());
                empSalary.setBasicSalary(emp.getBasicSalary());
                model.addRow(empSalary.toVector());
                listEmpSalary.add(empSalary);
            }
                      
        } else {
            // enable button calculate
            btnCalculate.setEnabled(false);
            btnExport.setEnabled(true);
            currentSalaryForm = salaryForm;
            List<EmployeeSalaryEntity> ls = new EmployeeSalaryList().getEmployeeSalaryBySalaryForm(salaryForm.getSalaryFormId());
            for (EmployeeSalaryEntity empS : ls) {
                EmployeeEntity emp = new EmployeeList().getEmployeeById(empS.getEmployeeId());
                empS.setEmployeeName(emp.getName());
                empS.setBonusSalary(emp.getBonusSalary());
                empS.setBasicSalary(emp.getBasicSalary());
                model.addRow(empS.toVector());
                listEmpSalary.add(empS);
            }
        }
    }
    
    private boolean validateLoadData() {
        if ((chooserMonth.getMonth() > Calendar.getInstance().get(Calendar.MONTH)&&chooserYear.getYear() == Calendar.getInstance().get(Calendar.YEAR)) || 
                chooserYear.getYear() > Calendar.getInstance().get(Calendar.YEAR)) {
            JOptionPane.showMessageDialog(null, "Can't choose day in the future !");
            return false;
        }
        return true;
    }
    
    private float getTotalAnualLeaveOfEmployee(String employeeId) {
        float totalAnualLeave = 0;
        List<SalaryFormEntity> listSalaryForm = new SalaryFormList().getSalaryFormByYear(Calendar.getInstance().get(Calendar.YEAR));
        
        for (SalaryFormEntity salaryForm : listSalaryForm) {
            float anualLeave = new EmployeeSalaryList().getEmployeeSalaryByFormAndEmpId(salaryForm.getSalaryFormId(), employeeId).getDayOffInspect();
            totalAnualLeave += anualLeave;
        }
        
        return totalAnualLeave;
    }
    
    private void getMaxDaysInMonth() {
        
        
        Calendar cal = Calendar.getInstance();
        cal.set(year, month, 1);
        int days = cal.getActualMaximum(Calendar.DAY_OF_MONTH);

        SpinnerNumberModel model = new SpinnerNumberModel(21, 0, days, 1);

        sprinnerWorkingDay.setModel(model);
    }
    
    
    
}
